import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.TokenStreamRewriter;

import java.util.HashMap;
import java.util.Map;


/*
 * 改写内容：
 * 1、把所有英文类型替换成中文类型
 * */

public class Cymbol语言改写器 extends CymbolBaseListener {

    public Cymbol语言改写器(CommonTokenStream tokenStream) {
        改写器 = new TokenStreamRewriter(tokenStream);
    }

    private final TokenStreamRewriter 改写器;

    public String 取改写后结果() {
        return 改写器.getText();
    }

    private final static Map<String, String> 类型翻译 = new HashMap<>() {{
        put("int", "整数型");
        put("float", "浮点型");
        put("char", "字符型");
        put("boolean", "字符型");
        put("void", "空");
    }};


    @Override
    public void enterPrimitiveType(CymbolParser.PrimitiveTypeContext ctx) {
        改写器.replace(ctx.start, 类型翻译.get(ctx.getText()));
    }
}
